package com.buzz.middleware.register;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @Author: LiBaoxuan
 * @CreateTime: 2025-04-13  15:10
 * @Description: TODO
 */
@Component
public class RegisterService implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @PostConstruct
    public void init() {
        String resourceType = applicationContext.getEnvironment().getProperty("platform.resourceType");
        String contextPath = applicationContext.getEnvironment().getProperty("server.servlet.context-path");
        stringRedisTemplate.opsForValue().set(resourceType, contextPath);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

}
